Data Backup
2701
12-May-2011
How to take backup of sel server 2005
Updated on 14-May-2011
Amresh Kushwaha
14-May-2011Anonymous User
13-May-2011Write down following code snippet in c# to take backup. One thing remeber that creadential should be changed..
using System; using System.Data; using System.Collections;using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo;
class Program { static void Main(string[] args) { BackupDeviceItem bdi = new BackupDeviceItem("AdventureWorks.bak", DeviceType.File);
Backup bu = new Backup( ); bu.Database = "AdventureWorks"; bu.Devices.Add(bdi); bu.Initialize = true;
// add percent complete and complete event handlers bu.PercentComplete += new PercentCompleteEventHandler(Backup_PercentComplete); bu.Complete +=new ServerMessageEventHandler(Backup_Complete);
Server server = new Server("localhost"); bu.SqlBackup(server);
Console.WriteLine(Environment.NewLine + "Press any key to continue."); Console.ReadKey( ); }
protected static void Backup_PercentComplete( object sender, PercentCompleteEventArgs e) { Console.WriteLine(e.Percent + "% processed."); }
protected static void Backup_Complete(object sender, ServerMessageEventArgs e) { Console.WriteLine(Environment.NewLine + e.ToString( )); } }
Amresh Kushwaha
13-May-2011I want to command
Uttam Misra
13-May-2011